﻿package mortal.game.view.wizard.newPanel
{
    import Message.DB.Tables.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.ChallengeCopy.view.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.wizard.data.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;

    public class WizardSkillPart extends GSprite
    {
        private var _skillItem:WizardSkillItem;
        private var _starPanel:StarPointPanel;
        private var _skillAdvanceBtn:GLoadingButton;
        private var _activeWizardBtn:GLoadingButton;
        private var _xhclTxt:GTextFiled;
        private var _skillInfoTxt:GTextFiled;
        private var _levelUpItemtxt:GTextFiled;
        private var _levelUpItem:BaseItem;
        private var _currentWizardData:WizardData;

        public function WizardSkillPart()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._skillItem = UICompomentPool.getUICompoment(WizardSkillItem);
            this._skillItem.setBg(ImagesConst.EquipItemBg, 6, 6);
            this._skillItem.setSize(48, 48);
            this._skillItem.x = 60;
            this._skillItem.y = 50;
            this.addChild(this._skillItem);
            this._starPanel = UIFactory.getUICompoment(StarPointPanel);
            this._starPanel.x = 124;
            this._starPanel.y = 61;
            this.addChild(this._starPanel);
            this._starPanel.setStarStyle(ImagesConst.WiardStarLight, ImagesConst.WiardStarDark, 28);
            this._skillAdvanceBtn = UIFactory.gLoadingButton(ResFileConst.WizardStarUpBtn, 265, 42, 56, 58, this);
            this._skillAdvanceBtn.configEventListener(MouseEvent.CLICK, this.upgradeHandler);
            this._skillAdvanceBtn.drawNow();
            this._activeWizardBtn = UIFactory.gLoadingButton(ResFileConst.WizardActiveBtn, 265, 42, 56, 58, this);
            this._activeWizardBtn.drawNow();
            this._activeWizardBtn.configEventListener(MouseEvent.CLICK, this.activeSprite);
            this._activeWizardBtn.name = "activeWizardBtn";
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            _loc_1.size = 12;
            this._skillInfoTxt = UIFactory.gTextField("", 80, 15, 220, 35, this, _loc_1);
            this._xhclTxt = UIFactory.gTextField(Language.getString(35615), 82, 105, 150, 60, this, GlobalStyle.textFormatBai.center());
            this._levelUpItem = UICompomentPool.getUICompoment(BaseItem);
            this._levelUpItem.x = 194;
            this._levelUpItem.y = 101;
            this._levelUpItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this.addChild(this._levelUpItem);
            this._levelUpItemtxt = UIFactory.gTextField("", 237, 116, 50, 20, this, GlobalStyle.textFormatDanLan);
            LoaderHelp.addResCallBack(ResFileConst.wizard, this.showSkin);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._skillItem.dispose(param1);
            this._skillItem = null;
            this._starPanel.dispose(param1);
            this._starPanel = null;
            this._skillInfoTxt.dispose(param1);
            this._skillInfoTxt = null;
            this._skillAdvanceBtn.dispose(param1);
            this._skillAdvanceBtn = null;
            this._activeWizardBtn.name = "";
            this._activeWizardBtn.dispose(param1);
            this._activeWizardBtn = null;
            this._xhclTxt.dispose(param1);
            this._xhclTxt = null;
            this._levelUpItem.dispose(param1);
            this._levelUpItem = null;
            this._levelUpItemtxt.dispose(param1);
            this._levelUpItemtxt = null;
            this._currentWizardData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function showSkin() : void
        {
            if (isDisposed)
            {
                return;
            }
            var _loc_1:* = UIFactory.gBitmap(ImagesConst.WizardSkillBg, 0, 0);
            this.addChildAt(_loc_1, 0);
            this.pushUIToDisposeVec(_loc_1);
            return;
        }// end function

        private function activeSprite(event:MouseEvent) : void
        {
            if (this._currentWizardData)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WizardItemUse, this._currentWizardData));
            }
            return;
        }// end function

        private function upgradeHandler(event:MouseEvent) : void
        {
            if (this._currentWizardData == null)
            {
                return;
            }
            if (!this._currentWizardData.isHasWizard)
            {
                MsgManager.showRollTipsMsg(Language.getString(30411));
                return;
            }
            if (event.target == this._skillAdvanceBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WizardUpgradeSkill, this._currentWizardData));
            }
            return;
        }// end function

        public function set data(param1:WizardData) : void
        {
            this._currentWizardData = param1;
            return;
        }// end function

        private function visibleInitialization() : void
        {
            this._activeWizardBtn.visible = true;
            this._levelUpItemtxt.visible = true;
            this._skillAdvanceBtn.visible = true;
            this._xhclTxt.visible = true;
            this._levelUpItem.visible = true;
            return;
        }// end function

        public function refreshSprite() : void
        {
            this.visibleInitialization();
            if (this._currentWizardData.isHasWizard)
            {
                this._activeWizardBtn.visible = false;
            }
            else
            {
                this._skillAdvanceBtn.visible = false;
            }
            return;
        }// end function

        public function updateSkill(param1:Boolean = true) : void
        {
            var _loc_2:* = SkillConfig.instance.getInfoById(this._currentWizardData.tSpriteEx.xpskillId);
            var _loc_3:* = new SkillInfo();
            _loc_3.tSkill = _loc_2;
            this._skillItem.skillInfo = _loc_3;
            this._starPanel.totalStar = WizardConfig.instance.getSkillTotalStar(this._currentWizardData.code);
            if (this._currentWizardData.isHasWizard)
            {
                this._starPanel.value = this._currentWizardData.spriteInfo.skillCode;
                this._skillInfoTxt.text = this._starPanel.value + Language.getStringByParam(35616, _loc_3.skillName);
                if (param1)
                {
                    EffectManager.glowFilterReg(this._skillItem, null, 1, 10, 0, 3);
                }
            }
            else
            {
                this._starPanel.value = 0;
                this._skillInfoTxt.text = "";
            }
            if (this._currentWizardData.isMaxStar)
            {
                this._levelUpItemtxt.visible = false;
                this._xhclTxt.visible = false;
                this._levelUpItem.visible = false;
            }
            else
            {
                this.updateItemHandler();
            }
            return;
        }// end function

        public function updateItemHandler() : void
        {
            var _loc_1:TSpriteEx = null;
            if (this._currentWizardData == null || this._currentWizardData.isMaxStar)
            {
                return;
            }
            if (this._currentWizardData.isHasWizard)
            {
                _loc_1 = WizardConfig.instance.getTSpriteExByCodeAndStar(this._currentWizardData.code, (this._currentWizardData.spriteInfo.skillCode + 1));
            }
            else
            {
                _loc_1 = WizardConfig.instance.getTSpriteExByCodeAndStar(this._currentWizardData.code, 1);
            }
            this._levelUpItem.itemData = new ItemData(_loc_1.prop);
            this._levelUpItemtxt.htmlText = "*" + _loc_1.amount;
            this._xhclTxt.htmlText = Language.getString(35617) + ItemsUtil.getItemName(this._levelUpItem.itemData);
            var _loc_2:* = Cache.instance.pack.backPackCache.getItemCountByItemCode(_loc_1.prop);
            if (_loc_2 >= _loc_1.amount)
            {
                this._levelUpItem.bitmap.filters = [];
                if (this._currentWizardData.isHasWizard)
                {
                    EffectManager.glowFilterReg(this._skillAdvanceBtn, null, 1, 10, 0);
                    this._skillAdvanceBtn.enabled = true;
                }
                else
                {
                    EffectManager.glowFilterReg(this._activeWizardBtn, null, 1, 10, 0);
                    this._activeWizardBtn.enabled = true;
                }
                this._levelUpItem.amount = _loc_2;
            }
            else
            {
                this._levelUpItem.bitmap.filters = [FilterConst.colorFilter2];
                EffectManager.glowFilterUnReg(this._skillAdvanceBtn);
                EffectManager.glowFilterUnReg(this._activeWizardBtn);
                var _loc_3:Boolean = false;
                this._activeWizardBtn.enabled = false;
                this._skillAdvanceBtn.enabled = _loc_3;
                this._levelUpItem.setAmountLabel("<font color=\'#df2121\'>" + _loc_2 + "</font>");
            }
            return;
        }// end function

        public function get starUpBtn() : GLoadingButton
        {
            return this._skillAdvanceBtn;
        }// end function

        public function showFilter(param1:int) : void
        {
            switch(param1)
            {
                case WizardNewInfoPanel.starPanel:
                {
                    EffectManager.glowFilterReg(this._starPanel, [FilterConst.redTipsFilter], 1, 10, 0, 3);
                    break;
                }
                case WizardNewInfoPanel.levelUpItemtxt:
                {
                    EffectManager.glowFilterReg(this._levelUpItemtxt, [FilterConst.redTipsFilter], 1, 10, 0, 3);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
